// pages/my/familyManage.js
const app = getApp();
import { getDocumentRectInfo } from '../../../utils/util'
var topOpacity = 0;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 组件参数设置，传递到组件
    defaultData: {
      title: "家人管理", // 导航栏标题
      showHome: false, //是否显示回到首页按钮
      showBack: true, //是否显示返回按钮
      showLogo: false, //是否显示logo
      bgColor: 'transparent'
    },
    baseUrl: app.baseUrl,
    version: app.globalData.version,
    navBarHeight: app.globalData.navBarHeight,
    showMonment: true,
    checkList: [
      {
        check: false,
        name: '门禁开启:可以开启组团及对应单元门禁，请慎重授权，确保安全使用'
      },
      {
        check: false,
        name: '访客邀请:受邀人员可邀请其他访客进出组团及单元楼栋，需确认受邀人员身份及安全车辆管理:可绑定车牌号进出组团，需遵守'
      },
      {
        check: false,
        name: '文明停车规约，不占用通道或他人私家车位停车'
      },
      {
        check: false,
        name: '会员卡权益:可使用业主相关权益，可使用已有会员卡，请知悉可能存在刷取储值卡余额或会员卡折扣的情况'
      },
      {
        check: false,
        name: '家庭信息:可查阅房屋地址、家庭成员信息及电话、车辆信息等，请知悉受邀人将共享家庭信息'
      }
    ],
    showMaintenance: false,
    listHeight: 500,
    tabIndex: 1,
    addList: [
      {
        id: 1,
        title1: '邀请成员加入',
        title2: '业主发起邀请->成员填写信息加入',
      },
      {
        id: 2,
        title1: '直接添加成员',
        title2: '需填写用户证件信息(身份证、护照、军官证台湾居民通行证、港澳居民通行证、其他)',
      }
    ],
    selectFamily: 1,
    addShowPop: false,
    addShowFamily: false,
    familyRelationship: [
      {
        id: 1,
        title1: '业主配偶',
        num1: 1,
        num2: 2,
      },
      {
        id: 2,
        title1: '业主父母',
        num1: 1,
        num2: 2,
      },
      {
        id: 3,
        title1: '业主子女',
        num1: 3,
        num2: 2,
      },
      {
        id: 4,
        title1: '其他成员',
        num1: 1,
        num2: 2,
      }
    ],
    relationshipIndex: 1,
    familyRelationShow: false,
    familyName: ''
  },
  onPageScroll(t) {
    if (t.scrollTop < 40) {
      topOpacity = 0
      if (this.data.topOpacity != 0) {
        this.setData({
          topOpacity: 0
        })
      }
    } else if (t.scrollTop >= 40) {
      if (topOpacity <= 1) {
        topOpacity = t.scrollTop / 100 - .4
      } else {
        topOpacity = 1
      }
      if (topOpacity <= 1) {
        this.setData({
          topOpacity: topOpacity
        })
      }
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var that = this;

  },
  // 删除
  removeItem(){

  },
  // 完善信息
  completeinfor(){
    wx.navigateTo({
      url: '/pages/my/add-residents/add-residents',
    })
  },
  selectPopFamily() {
    this.setData({
      familyRelationShow: true
    })
  },
  relationshipBtn() {
    const { relationshipIndex, familyRelationship } = this.data
    this.setData({
      familyRelationShow: false,
      familyName: familyRelationship.find(el=>el.id==relationshipIndex).title1
    })
  },
  relationshipIiem(e) {
    const { id } = e.currentTarget.dataset
    this.setData({
      relationshipIndex: id
    })
  },
  familyBtn() {
    this.setData({
      addShowFamily: false
    })
  },
  familyClose() {
    this.setData({
      addShowFamily: false
    })
  },
  addNember() {
    this.setData({
      addShowPop: true
    })
  },
  popNext() {
    const {selectFamily}=this.data
    this.setData({
      addShowPop: false
    })
    // selectFamily
    if(selectFamily==1){
      this.setData({
        addShowPop: false,
        addShowFamily:true
      })
    }else{
      this.setData({
        addShowPop: false,
      })
      wx.navigateTo({
        url: '/pages/my/add-residents/add-residents',
      })
    }
  },
  popCha() {
    this.setData({
      addShowPop: false
    })
  },
  statementItem(e) {
    const { id } = e.currentTarget.dataset
    this.setData({
      selectFamily: id
    })
  },
  tabHand(e) {
    const { index } = e.currentTarget.dataset
    this.setData({
      tabIndex: index
    })
  },
  maintenance() {
    this.setData({
      showMaintenance: false
    })
  },
  popclose() {
    this.setData({
      showMaintenance: false
    })
  },
  checkHand(e) {
    const { index } = e.currentTarget.dataset
    const { checkList } = this.data
    checkList[index].check = !checkList[index].check
    this.setData({
      checkList
    })
  },
  disagree() {
    this.setData({
      showMonment: false
    })
  },
  agree() {
    const { checkList } = this.data
    if (!checkList.every(el => el.check)) {
      wx.showToast({
        title: '请全部勾选',
        icon: 'none'
      })
      return
    }
    this.setData({
      showMonment: false
    })
  },
  async onReady() {
    const { windowHeight } = wx.getSystemInfoSync();
    const searchInfo = await getDocumentRectInfo('.kong', this)
    console.log(windowHeight);
    console.log(searchInfo);
    this.setData({
      listHeight: windowHeight - searchInfo.bottom
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    var that = this;
    //刷新邀请id
    if (that.data.mySf == '业主') {
      that.fleshBillId();
    }
    return {
      title: that.data.shareTitle,
      path: '/pages/my/familyInvite?familyId=' + that.data.familyId + "&shareOpenid=" + that.data.openid + '&billId=' + that.data.billId,
      imageUrl: that.data.shareImg,
      success: function (res) {

      },
      fail: function (res) {

      }
    }
  }
})